import apis from '../../http/apis.js'
export default {
    async getAdmins(context) {
        const pages = context.state.pages;
        const searchData = context.state.searchData;
        const { data } = await apis.admins.getAllAdmins({
            ...searchData,
            currentPages: pages.currentPages,
            pageData: pages.pageData,
        });
        // console.log(data, 'data');
        if (data.status) {
            context.commit('changeAdminData', data.data)
        }
    },

    async getOneAdmin(context, _id) {

        const { data } = await apis.admins.getAllAdmins({ _id });

        if (data.status) {
            context.commit('changeAdminData', data.data)
        }
    },
    async addAdmins(context, admins) {
        const { data } = await apis.admins.addAdmins(admins);

        if (data.status) {
            context.dispatch("getAdmins")
        }
        return data
    },
    async changeAdmins(context, { _id, ...update }) {
        const { data } = await apis.admins.modifyAdmins({ _id, update });
        if (data.status) {
            alert('修改成功');
            location.hash = '/system/AdminList'
        }
    },
    async delAdmins(context, _id) {
        const { data } = await apis.admins.delAdmins({ _id })
        // console.log({ _id }, '删除');
        if (data.status) {
            context.dispatch("getAdmins")
        }
    },
    //changeState
    async changeState(context, _id) {
        const { data } = await apis.admins.changeState({ _id })
        // console.log({ _id }, '删除');
        if (data.status) {
            context.dispatch("getAdmins")
        }
    },
}